<% content_for :css do %>
  <%= stylesheet_link_tag 'index','employees_index' %>
<% end %>
<div class='body'>
  <div class='top'>
    <div class='title'>
      <b>系统设置</b><span>企业员工</span>
    </div>
  </div>
  <div class="search">
    <%= form_tag employees_url,
          :method => :get do %> 
      <%= hidden_field_tag :target, params[:target] %>
      <%= text_field_tag :key_words, params[:key_words] ,:class => :search, :onfocus => 'select()' %>
      <%= submit_tag '查找员工', :class => :bb %>
      <%= link_to '新增员工', new_employee_url,  :class => :new %>
    <% end %>
  </div> 
  <div class="page">
    <div class="total_currnet"><p>共</p><b><%= @employees.size %></b><p>名员工</p></div>
  </div>   
  <div class="index">  
    <% @employees.each do |employee| %>
    <div id='employee_<%= employee.id %>' class="monomer">
      <div class="content">
        <div class="title">
          <div class="name">
            <b><%= employee.full_name %></b>
          </div>
          <div class="information">
            <p class="statistics">
              <%= employee.mobile %>
            </p>
            <p class="statistics">
              <%= t employee.sex %>
            </p>
            <p class="message">
              <%= employee.address %>
            </p>
          </div>
        </div>      
        <div class="article">
          <table cellspacing="1" cellpadding="1">
            <tr>
              <th>部门</th>
              <th colspan='3'>岗位</th>
            </tr>            
            <% Dept::Storefront.visible.order('type asc').each do |dept| %>
              <% if employee.posts_by_dept_id(dept.id).any? %>
              <tr>
                <td class='dept'><%= dept.name %></td>                
                <td>
                  <%= employee.is_saler?(:dept_id => dept.id) ? t(:saler) : '' %>
                </td>
                <td>
                  <%= employee.is_officer?(:dept_id => dept.id) ? t(:officer) : '' %>
                </td>
                <td>
                  <%= employee.is_installer?(:dept_id => dept.id) ? t(:installer) : '' %>
                </td>
              </tr>
              <% end %>
            <% end %>
            <% Dept::Storehouse.visible.order('type asc').each do |dept| %>   
              <% if employee.posts_by_dept_id(dept.id).any? %>         
              <tr>
                <td class='dept'><%= dept.name %></td>
                <td colspan='3'>
                  <%= employee.is_store_admin?(:dept_id => dept.id) ? t(:store_admin) : '' %>
                </td>
              </tr>
              <% end %>
            <% end %>
            <% if employee.posts.empty? %>
            <tr>
              <td class='no_record' colspan='4'>无</td>
            </tr>
            <% end %>
          </table>
        </div>
        <div class="article">
          <%= employee.remark %>
        </div>
      </div>
      <div class="operate">
        <%= link_to '修改',edit_employee_url(employee), :class => 'button' %>
        <% if employee.status.visible? %>
        <%= link_to '隐藏',
              hide_employee_url(employee),
              :confirm => '确认要设置为隐藏吗？',
              :method => :put,
              :class => 'button',
              :id => "hide_employee_#{employee.id}_link"
         %>
         <% else %>
         <%= link_to '可见',
              visible_employee_url(employee),
              :confirm => '确认要设置为可见吗？',
              :method => :put,
              :class => 'button',
              :id => "visible_employee_#{employee.id}_link"
         %>
         <% end %>
      </div>
    </div>
    <% end %>
  </div>
  <div class="page">
    <div class="total_currnet"><p>共</p><b><%= @employees.size %></b><p>名员工</p></div>
  </div>     
</div>

        